



#include "ADC_Driver.h"


void initADC(void)
{
	ADCON1bits.VCFG0 = 0;		//Sets GND as negative reference
	ADCON1bits.VCFG1 = 0;		//Sets Vcc as positive reference
	ADCON2bits.ADFM = 0;		//Sets the justified result
	ADCON2bits.ADCS2 = 0;
	ADCON2bits.ADCS1 = 1;		//Sets the internal ADC clock
	ADCON2bits.ADCS0 = 1;
}


T_UWORD getADCvalue(T_UBYTE channel)
{
	T_UBYTE		channel1,channel2,channel3,channel4;
	T_UWORD	value;
	
	channel1 =	channel & 0x01;
	channel2 =	(channel & 0x02) >> 1;
	channel3 =	(channel & 0x04) >> 2;
	channel4 =	(channel & 0x08) >> 3;

	ADCON0bits.CHS3 = channel4;
	ADCON0bits.CHS2 = channel3;
	ADCON0bits.CHS1 = channel2;
	ADCON0bits.CHS0 = channel1;
	
	ADCON0bits.ADON = 1;
	
	while(ADCON0bits.GO_DONE != 1){};
	
	ADCON0bits.ADON = 0;
	
	return ADRES;

}